//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo40AND60;

public class demo_58 {
    public demo_58() {
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLastWord("Hello World"));
        System.out.println(lengthOfLastWord2("Hello World"));
    }

    public static int lengthOfLastWord(String s) {
        s = s.trim();
        int con = 0;

        for(int i = s.length() - 1; i > 0 && s.charAt(i) != ' '; --i) {
            if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z' || s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
                ++con;
            }
        }

        return con;
    }

    public static int lengthOfLastWord2(String s) {
        s = s.trim();
        return s.length() - 1 - s.lastIndexOf(32);
    }
}
